from pydantic_settings import BaseSettings
from typing import List
import os


class Settings(BaseSettings):
    """应用程序配置"""

    # 应用基本配置
    APP_NAME: str = "Demo Backend API"
    DEBUG: bool = True
    HOST: str = "127.0.0.1"
    PORT: int = 8888

    # 服务器URL配置
    BASE_URL: str = f"http://127.0.0.1:8888"

    # 数据库配置
    DATABASE_URL: str = "mysql+pymysql://root:Akimixu198972@localhost:3306/demo_backend"
    # 如果要使用 SQLite，可以这样配置：
    # DATABASE_URL: str = "sqlite:///./demo_backend.db"
    # 如果要使用 PostgreSQL，可以这样配置：
    # DATABASE_URL: str = "postgresql+asyncpg://username:password@localhost/demo_backend"

    # JWT 配置
    SECRET_KEY: str = "your-secret-key-here-change-in-production"
    ALGORITHM: str = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
    REFRESH_TOKEN_EXPIRE_DAYS: int = 7

    # CORS 配置
    ALLOWED_HOSTS: List[str] = ["*"]  # 生产环境中应该指定具体的域名

    # 文件上传配置
    UPLOAD_DIR: str = "uploads"
    MAX_FILE_SIZE: int = 10 * 1024 * 1024  # 10MB
    ALLOWED_FILE_TYPES: List[str] = [
        "image/jpeg",
        "image/png",
        "image/gif",
        "application/pdf",
        "text/plain",
        "application/msword",
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    ]

    # 日志配置
    LOG_LEVEL: str = "INFO"

    class Config:
        env_file = ".env"
        case_sensitive = True


# 创建设置实例
settings = Settings()
